<template>
  <view class="bd">
    <view class="box bd1">
      <view class="flex flex-al-c">
        <view class="btn active" @tap="goCalendar">
          <image
            src="../../../static/img/33c56eba4a994d8a9855399cd75984bf.png"
            mode="widthFix"
            style="width: 100upx"
          ></image>
          <view>预约接种</view>
        </view>
      </view>
      <view class="flex flex-al-c">
        <view class="btn active" @tap="goCalendar1">
          <image
            src="../../../static/img/tjmanager.png"
            mode="widthFix"
            style="width: 100upx; filter: blur(1rpx)"
          ></image>
          <view>预约体检</view>
        </view>
      </view>
      <view class="flex flex-al-c">
        <view class="btn active" @tap="goCalendar2">
          <image
            src="../../../static/img/ae99ff3a658d4456899e0d2a1f8554e7.png"
            mode="widthFix"
            style="width: 100upx"
          ></image>
          <view>预约门诊</view>
        </view>
      </view>
      <view class="flex flex-al-c" v-for="item in navList">
        <view class="btn active" @tap="goCalendar2('', item.deptId, item.name)">
          <image
            src="../../../static/img/ae99ff3a658d4456899e0d2a1f8554e7.png"
            mode="widthFix"
            style="width: 100upx"
          ></image>
          <view>{{ item.name }}</view>
        </view>
      </view>
      <view style="height: 300upx"></view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      sq: "",
      navList: [],
    };
  },
  onLoad() {
    this.shequ();
    this.getAnyId();
  },
  onReady() {
    // this.getUiStyle();
  },
  methods: {
    getUiStyle() {
      var style = plus.navigator.getUiStyle();
      if ("dark" == style) {
        console.log("当前为暗黑模式");
        uni.setTabBarStyle({
          backgroundColor: "#1B1C1E",
        });
        uni.setNavigationBarColor({
          frontColor: "#ffffff",
          backgroundColor: "#1B1C1E",
          animation: {
            duration: 400,
            timingFunc: "easeIn",
          },
        });
      } else {
        console.log("当前为普通模式");
      }
    },
    //获取社区
    shequ() {
      uni.showLoading({
        title: "加载中",
        mask: true,
      });
      setTimeout((s) => {
        uni.hideLoading();
      }, 5000);
      this.config.get("/common/getUserInfo/getDeptInfo", {}).then((res) => {
        uni.hideLoading();
        if (res.data.code === 200) {
          this.sq = res.data.data.deptName;
        } else {
          if (res.data.code == "-201") {
            self.config.handleError(res.data);
          } else {
            uni.showToast({
              title: self.config.handleError(res.data),
              icon: "none",
            });
          }
        }
      });
    },
    goCalendar() {
      let self = this;
      uni.showLoading({
        title: "加载中",
        mask: true,
      });
      setTimeout((s) => {
        uni.hideLoading();
      }, 5000);
      this.config
        .get("/subscribesInfos/ifCanSub", {
          planType: 8,
        })
        .then((res) => {
          uni.hideLoading();
          if (res.data.code === 200) {
            if (res.data.data.state == 0 || res.data.data.state == 2) {
              uni.navigateTo({
                url: "./yuyueym",
              });
            } else {
              uni.showToast({
                title: "您暂有未完成的计划预约，不可再次预约",
                icon: "none",
              });
            }
          } else {
            if (res.data.code == "-201") {
              self.config.handleError(res.data);
            } else {
              uni.showToast({
                title: self.config.handleError(res.data),
                icon: "none",
              });
            }
          }
        });
    },
    goCalendar1() {
      let self = this;
      uni.showLoading({
        title: "加载中",
        mask: true,
      });
      setTimeout((s) => {
        uni.hideLoading();
      }, 5000);
      this.config
        .get("/subscribesInfos/ifCanSub", {
          planType: 7,
        })
        .then((res) => {
          uni.hideLoading();
          if (res.data.code === 200) {
            if (res.data.data.state == 0 || res.data.data.state == 2) {
              uni.navigateTo({
                url: "./yuyuetj",
              });
            } else {
              uni.showToast({
                title: "您暂有未完成的计划预约，不可再次预约",
                icon: "none",
              });
            }
          } else {
            if (res.data.code == "-201") {
              self.config.handleError(res.data);
            } else {
              uni.showToast({
                title: self.config.handleError(res.data),
                icon: "none",
              });
            }
          }
        });
    },
    goCalendar2(type, deptId, deptName) {
      let self = this;
      uni.showLoading({
        title: "加载中",
        mask: true,
      });
      setTimeout((s) => {
        uni.hideLoading();
      }, 5000);
      let planType = "";
      if (type != "") {
        planType = 12;
      }
      this.config
        .get("/subscribesInfos/ifCanSub", {
          planType: planType,
          deptId: deptId,
        })
        .then((res) => {
          uni.hideLoading();
          if (res.data.code === 200) {
            if (res.data.data.state == 0 || res.data.data.state == 2) {
              if (type) {
                uni.navigateTo({
                  url:
                    "/pages/main/child/backlog/calendar?type=12&name=预约门诊&sq=" +
                    this.sq +
                    "&comeuser=" +
                    "old" +
                    "&vPid=" +
                    "",
                });
              } else {
                uni.navigateTo({
                  url:
                    "/pages/main/child/backlog/calendar?type=" +
                    type +
                    "&name=" +
                    deptName +
                    "&sq=" +
                    this.sq +
                    "&deptId=" +
                    deptId +
                    "&comeuser=" +
                    "old" +
                    "&vPid=" +
                    "",
                });
              }
            } else {
              uni.showToast({
                title: "您暂有未完成的计划预约，不可再次预约",
                icon: "none",
              });
            }
          } else {
            if (res.data.code == "-201") {
              self.config.handleError(res.data);
            } else {
              uni.showToast({
                title: self.config.handleError(res.data),
                icon: "none",
              });
            }
          }
        });
    },
    //获取动态科室
    getAnyId() {
      this.config.get("/getSysDept/getOther", {}).then((res) => {
        console.log(res);
        for (let i = 0; i < res.data.data.length; i++) {
          if (
            res.data.data[i].population == 0 ||
            res.data.data[i].population == 4
          ) {
            let datas = {
              name: res.data.data[i].deptName,
              deptId: res.data.data[i].deptId,
            };
            this.navList.push(datas);
          }
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.box {
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  width: 88px;
  height: 88px;
  margin: 40rpx 0 30rpx 124rpx;
  background-color: #ccc;
  border-radius: 15upx;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  font-weight: 900;
  color: #fff;
}

.btn.active {
  background-color: #18c7e1;
}
</style>
<style scoped>
@media (prefers-color-scheme: closedark) {
  .bd {
    background-color: #1b1c1e !important;
    height: calc(100vh - var(--window-top));
  }
  .b1 {
    background-color: #1b1c1e !important;
  }
  .t1 {
    color: #ccc !important;
  }
  .btn.active {
    background-color: #1b1c1e !important;
    box-shadow: 0px 0px 4px 1px #18c7e1;
  }
}
</style>